

import { isPlainObject } from '../../util/index'
import { ASSET_TYPES } from '../../util/constants'

//全局组件，全局过滤器，全局指令
export function initAssetRegisters (Vue) {
  ASSET_TYPES.forEach(type => {
    Vue[type] = function (
      id,
      definition
    ) {
      this.options[type + 's'] = Object.create(null)
      if (!definition) {
        return this.options[type][id]
      } else {
        if (type === 'component' && isPlainObject(definition)) {
          definition.name = definition.name || id
          definition = this.options._base.extend(definition)
        }
        this.options[type + 's'][id] = definition
        return definition
      }
    }
  })
}
